package digui;

public class huishumigong {
    public static void main(String[] args) {
        int arr [] [] = new int[6][8];

        for (int i = 0 ; i < 8 ; i++){
            arr[0][i]=1;
            arr[5][i]=1;
        }
        for (int i = 0 ; i < 6 ; i++){
            arr[i][0]=1;
            arr[i][7]=1;
        }
        arr[2][1]=1;
        arr[2][2]=1;
        //回溯
//        arr[1][2]=1;
        for (int i = 0; i < 6; i++) {
            for (int j = 0 ; j < 8 ; j++){
                System.out.print(arr[i][j]);
            }
            System.out.println();
        }
        System.out.println();
        makeRaod(arr,1,1);
        for (int i = 0; i < 6; i++) {
            for (int j = 0 ; j < 8 ; j++){
                System.out.print(arr[i][j]);
            }
            System.out.println();
        }

    }
    public static boolean makeRaod(int[][] arr, int i, int j){
        if(arr[4][6]==2){
            return true;
        }else {
            if(arr[i][j]==0){
                arr[i][j]=2;
                if(makeRaod(arr,i+1,j)){
                    return true;
                }else if(makeRaod(arr,i,j+1)){
                    return true;
                }else if(makeRaod(arr,i-1,j)){
                    return true;
                }else if(makeRaod(arr,i,j-1)){
                    return true;
                }else {
                    arr[i][j]=3;
                    return false;
                }
            }else {
                //可能是1 2 3
                return false;
            }
        }

    }
}
